<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<link rel="stylesheet" type="text/css" href="<%=basePath%>img/from.css">
<script type="text/javascript">
	function readCardInfo(){
		var cardid = findNormalCard();
		if(cardid){
			$('#abaid').val(cardid);
			return true;
		}return false;
	}
	function queryInfo(){
		var r = $('#ff').form('validate');
		if(!r) {
			return false;
		}
		if($('#abaid').val()=='' && $('#ownercard').val()=='')
		{
			$.messager.alert('提示','一卡通卡号和有效证号必须输入一个。','info');
			return false;
		}
		$("#resultInfo").show();
		$.post("aba/cardChangeQ",$("#ff").serializeArray(),function(data){
			if (typeof(data.username) == "undefined") {
				$("#userInfo").hide();
			}else
			{
				$("#userInfo").show();
				$("#username").text(data.username);
				$("#ownercardText").text(data.ownercard);
				if(data.sex == "1")
				{
					$("#sex").text("男");
				}else if(data.sex == "0")
				{
					$("#sex").text("女");
				}else
				{
					$("#sex").text("不明");
				}		
				$("#telephone").text(data.telephone);			
			}

			
			if (typeof(data.aba) == "undefined") {
				$("#cardInfo").hide();
				$('#abaTable').datagrid('loadData', {total:0, rows:[]});   
				return;
			}
			$("#cardInfo").show();
			$('#abaTable').datagrid({
				 singleSelect:true,//多选
				 fitColumns: true,
				 columns:[[
				           {title:'卡号',field:'abaid',width:180,align:'center'},
				           {title:'userid',field:'userid',width:180,align:'center',hidden:true},
				           {title:'cardpassword',field:'cardpassword',width:180,align:'center',hidden:true},
				           {title:'version',field:'version',width:180,align:'center',hidden:true},
				           {title:'moneycardlimit',field:'moneycardlimit',width:180,align:'center',hidden:true},
				           {title:'挂失日期',field:'losteddate',width:180,align:'center'},
				           {title:'cardkey',field:'cardkey',width:180,align:'center',hidden:true},
		                   {title:'开卡日期',field:'creatdatetime',width:180,align:'center'},
		                   {title:'状态',field:'losted',width:180,
		    					formatter:function(value,row,index){
		    						if (row.losted==1) { 
		    							return "正常" ;
		    						}
		    						else if(row.losted == 2){ 
		    							return "挂失";
		    						}else{
		    							return "取消使用";
		    						}
		    					}
		    				},	
		                    {title:'电子账户金额',field:'emoney',width:180,align:'center'},
		                    {title:'电子钱包金额',field:'money',width:180,align:'center'},
		                    {title:'是否有电子账户',field:'eflag',width:180,align:'center',
		    					formatter:function(value,row,index){
		    						if (row.eflag==true) { 
		    							return "是";
		    						}else{
		    							return "否";
		    						}
		    					}
		    				}
				           ]]
			});
			$('#abaTable').datagrid('loadData', data.aba);   
		});
	}
	
    //更新
    function openChangeCard(){
		var rows = $('#abaTable').datagrid('getSelections');
		if(rows.length==0){
			$.messager.alert('提示',"请选择你要更换的卡",'info');
			return;
		}
		if(rows.length > 1){
			$.messager.alert('提示',"只能选择一个卡进行更新",'info');
			return;
		}
		//var date1 = new Date(Date.parse(rows[0].creatdatetime.replace(/-/g,"/")));
		//var date2=new Date();
		//var date3=date2.getTime()-date1.getTime();
		//var days=Math.floor(date3/(24*3600*1000));
		if(rows[0].losted != 2){
			$.messager.alert('提示',"此卡未挂失.",'info');
			return;
		}
		//if(days<=7)
		//{
		//	$.messager.alert('提示',"卡片挂失未到7天.",'info');
		//	return;
		//}
		rows[0]["creatuserid"] = '<sec:authentication property="name"/>';
		rows[0]["username"] = $("#username").text();
		
		if (rows[0].losted==1) { 
			rows[0]["lostedText"] = "正常" ;
		}else if(rows[0].losted == 2){ 
			rows[0]["lostedText"] = "挂失";
		}else{
			rows[0]["lostedText"] = "取消使用";
		}
		
    	$.post('aba/cardChangePopWindow?lostedDate='+rows[0]["losteddate"],function(data){
        	if(data.mes=="1"){
        		showWindow({
          			title:'换卡',
          			href:'aba/cardChangeO',
          			width:800,
          			height:450,
          			onLoad: function(){
          			//自动将数据填充到表单中，无需再查询数据库，这里需要注意：
          			//spring mvc中表单元素的名称不带对象前缀，直拉就是id，所以这里load的时候是：.form('load', rows[0].user)
          			$("#abaForm").form('load', rows[0]);
          			}
          		});        		
        	}else
       		{
        		$.messager.alert('提示',"卡片挂失未到7天.",'info');
       		}
    	});
	}  
     
    
	//清空查询条件
	function clearForm(){
		$('#ff').form('clear');
		$("#resultInfo").hide();
	}
</script>
<div style="background:#fafafa;padding:10px;">
	<div style="padding:3px 2px;margin-bottom:10px;border-bottom:1px solid #ccc"><div>换卡</div></div>
	<div style="background:#fafafa;">
	    <form id="ff" method="post">
			<table width="100%">
				<tr>
				 <td>一卡通卡号：<input id="abaid" name="abaid" style="width: 150"></input></td>
				 <td>有效证件号：<input id="ownercard" name="ownercard" style="width: 150"></input></td>
				</tr>
			</table>
	    </form>
	</div>
	<div style="margin:10px 0;">
		<a href="#" class="easyui-linkbutton" onclick="readCardInfo()" iconCls="icon-search">读卡</a> 
		<a href="#" class="easyui-linkbutton" onclick="queryInfo()" iconCls="icon-search">查询</a> 
		<a href="#" class="easyui-linkbutton" onclick="clearForm()" iconCls="icon-search">清空</a> 
	</div>
</div>
<div id="resultInfo" style="background:#fafafa;padding:10px;display:none;">
	<div id="userInfo"  style="background:#fafafa;">
		<table width="100%">
			<tr>
			 <td>姓名：</td><td id="username" width="200px"></td>
			 <td>有效证件号：</td><td id="ownercardText" width="200px"></td>
			 <td>性别：</td><td id="sex" width="200px"></td>
			 <td>移动电话：</td><td id="telephone" width="200px"></td>
			</tr>
		</table>
	</div>
	<div id="cardInfo"  style="padding:10" id="tabdiv">
		<table id="abaTable"></table>
		<div style="margin:10px 0;">
		 <a href="#" class="easyui-linkbutton" onclick="openChangeCard()" iconCls="icon-search">换卡</a> 
	    </div>	
	</div>
</div>